let express = require("express");
let sql = require("../conn/conn");
let path = require("path");

let router = express.Router();

router.get("/goodslist", (req, res, next) => {
	let result = sql("select * from product");
	result
		.then((data) => {
			res.send({ success: 1, msg: "获取商品成功", data });
		})
		.catch((err) => {
			console.log(err);
			res.send({ success: 0, msg: "获取商品失败" });
		});
});

router.get("/goodsdetail", (req, res, next) => {
	let { id } = req.query;
	let result = sql(`select * from product where id='${id}'`);
	result
		.then((data) => {
			res.send({ success: 1, msg: "获取商品详情成功", data });
		})
		.catch((err) => {
			console.log(err);
			res.send({ success: 0, msg: "获取商品详情失败" });
		});
});

router.get("/cartlist", (req, res, next) => {
	let { id_list } = req.query;
	let result = sql(`select * from product where id in (${id_list})`);
	result
		.then((data) => {
			res.send({ success: 1, msg: "获取商品详情成功", data });
		})
		.catch((err) => {
			console.log(err);
			res.send({ success: 0, msg: "获取商品详情失败" });
		});
});
module.exports = router;
